package com.jh.paymentchannel.util.jifu;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateTime {
	private static SimpleDateFormat defaultFormat = new SimpleDateFormat(
			"yyyy-MM-dd HH:mm:ss");

	public static String getNow() {
		Date date = new Date();
		return defaultFormat.format(date).toString();
	}

	public static String getNow(String formatStr) {
		Date date = new Date();
		try {
			SimpleDateFormat format = new SimpleDateFormat(formatStr);
			return format.format(date).toString();
		}
		catch (Exception e) {
		}
		return defaultFormat.format(date);
	}

	public static String getDate(Date date, String formatStr) {
		SimpleDateFormat format;
		try {
			format = new SimpleDateFormat(formatStr);
			return format.format(date).toString();
		}
		catch (Exception e) {
		}
		return defaultFormat.format(date);
	}

	public static Date parse(String date) throws ParseException {
		return defaultFormat.parse(date);
	}

	public static String getTenDate(){
		Date now = new Date();
		Date now_10 = new Date(now.getTime() - 1800000); //30����ǰ��ʱ��
		SimpleDateFormat dateFormat = new SimpleDateFormat("HHmmss");//���Է�����޸����ڸ�ʽ
		String nowTime_10 = dateFormat.format(now_10);
		return nowTime_10;
	}
	
	public static Date parse(String date, String formatStr)
			throws ParseException {
		SimpleDateFormat format = new SimpleDateFormat(formatStr);
		return format.parse(date);
	}
}